<template>
    <div class="my-on-trial-wrapper">
      <van-list
        v-model="isUploading"
        :finished="isUpfinished"
        :finished-text=" onTrialList.length === 0 ? '暂无数据' : '没有更多了' "
        @load="onLoad"
      >
        <ul>
          <li class="clearfix" v-for="(item,index) in onTrialList" :key="index">
            <div class="fl">
              <h4>
                <label class="fl" v-if="item.status === 1">申请中</label>
                <label class="fl" v-if="item.status === 2">试用中</label>
                <label class="fl unsigned" v-if="item.status === 3">未中签</label>
                <label class="fl unsigned" v-if="item.status === 5">已结束</label>
                {{item.title}}
              </h4>
              <p>{{item.result_at}}公布名单</p>
            </div>
            <router-link :to="{path:'/fill-in-report',query:{id:item.id}}" class="fr" v-if="item.status === 2">填写报告</router-link>
            <router-link :to="{path:'/fill-in-report',query:{id:item.id}}" class="fr" v-if="item.status === 5">填写报告</router-link>
          </li>
        </ul>
      </van-list>
    </div>
</template>

<script>
    import ajax from '../../module/ajax/public'
    import {Cell, CellGroup,Tag,List } from 'vant'

    export default {
        name: "OnTrial",
        components:{
          [Cell.name]: Cell,
          [CellGroup.name]: CellGroup,
          [Tag.name]: Tag,
          [List.name]: List,
        },
        mounted(){
          this.getOnTrailData();
        },
        data(){
          return {
            page:0,
            onTrialList:[],
            isUploading: false,
            isUpfinished:false,
            id:1
          }
        },
        methods:{
          getOnTrailData(){
            this.page++;
            ajax.doAction({
              url: `/user/labs?page=${this.page}`,
              type: 'POST',
              successCallback:(data)=>{
                // console.log(data);
                let datas = data.data;
                this.isUploading = false;
                if(datas.length >0){
                  this.onTrialList = this.onTrialList.concat(datas);
                }else{
                  this.isUpfinished = true;
                }
              },
              errorCallback: (data)=> {
                console.log('请求失败');
              }
            });
          },
          onLoad(){
            // console.log('上拉加载'+this.page);
            this.getOnTrailData();
          }
        }
    }
</script>

<style>
.my-on-trial-wrapper{
  padding:12px;
}
.my-on-trial-wrapper li{
  border-bottom: 1px solid #eee;
  padding: 12px 0;
  position: relative;
}
.my-on-trial-wrapper li h4{
  font-size: 15px;
  font-weight: normal;
  margin-bottom: 5px;
  line-height: 20px;
}
.my-on-trial-wrapper li label{
  color: #fff;
  text-align: center;
  width: 40px;
  line-height: 15px;
  background: #ef8a26;
  margin-right: 5px;
  font-size: 10px;
  border-radius: 3px;
}
.my-on-trial-wrapper li label.unsigned{
  background: #888;
}
.my-on-trial-wrapper li p{
  color: #999;
}
.my-on-trial-wrapper li a{
  position: absolute;
  right: 0;
  bottom: 12px;
  color: #0085ca;
  padding-top: 10px;
  margin-left: 5px;
}
</style>
